unit UDIBXVersion;

interface

uses
  SysUtils, Forms, Classes, IBServices;

type
  TDIBXVersion = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private declarations }
    IBBackupService: TIBBackupService;
    procedure Configure(AServerName, AUserName, APassword, ADBFile,
      ABKPFile: string);
    procedure Reset;
  public
    { Public declarations }
    procedure ProcessBackup(AServerName, AUserName, APassword, ADBFile,
      ABKPFile: string; Lines: TStrings);
  end;

var
  DIBXVersion: TDIBXVersion;

implementation

{$R *.dfm}

procedure TDIBXVersion.DataModuleCreate(Sender: TObject);
begin
  IBBackupService := TIBBackupService.Create(Self);
end;

procedure TDIBXVersion.ProcessBackup(AServerName, AUserName, APassword, ADBFile, ABKPFile: string;
  Lines: TStrings);
begin
  Reset;
  Configure(AServerName, AUserName, APassword, ADBFile, ABKPFile);
  with IBBackupService do
    try
      Active  := False;
      Active  := True;
      Verbose := True;
      Options := [NonTransportable, IgnoreLimbo];
      DatabaseName := ADBFile;
      BackupFile.Add(ABKPFile);
      ServiceStart;
      while not Eof do
      begin
        Lines.Add(GetNextLine);
        Application.ProcessMessages;
      end;
    finally
      Active := False;
    end;
end;

procedure TDIBXVersion.Reset();
begin
  with IBBackupService do
  begin
    ServerName := '';
    LoginPrompt := False;
    Params.Clear;
    DatabaseName := '';
    BackupFile.Clear;
  end;
end;

procedure TDIBXVersion.Configure(AServerName, AUserName, APassword, ADBFile, ABKPFile: string);
begin
  with IBBackupService do
  begin
    ServerName := AServerName;
    LoginPrompt := False;
    Params.Add('user_name=' + AUserName);
    Params.Add('password=' + APassword);
  end;
end;

procedure TDIBXVersion.DataModuleDestroy(Sender: TObject);
begin
  FreeAndNil(IBBackupService);
end;

end.
